<?php

namespace common\Factory\Logger;

use common\Factory\ServerInterface;

class LoggerServer implements ServerInterface {
    
    private $_config;
    
    function __construct() {
        $this->_config = \core\init\init::getConfig();
        $this->config();
    }
    
    private function config() {
        \Logger::configure(array(
            'rootLogger' => array(
                'appenders' => array($this->_config['log4php']['loggerName']),
            ),
            'appenders' => array(
                'default' => array(
                    'class' => 'LoggerAppenderRollingFile',
                    'layout' => array(
                        'class' => 'LoggerLayoutPattern',
                        'conversionPattern' => '%date{Y-m-d H:i:s} %logger %message%newline',
                    ),
                    'params' => array(
                        'file' => $this->_config['log4php']['filePath'],
                        'maxFileSize' => $this->_config['log4php']['maxFileSize'],
                        'maxBackupIndex' => $this->_config['log4php']['maxBackupIndex'],
                        'append' => true,
                    ),
                ),
            )
        ));
    }
    
    public function getObj() {
        return \Logger::getLogger($this->_config['log4php']['loggerName']);
    }
}